<template>
  <div>
    <!-- 车辆颜色维护 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTables ref="table" :columns="columns" :fetchapi="fetchApi" :params="fetchParams" :datakey="'records'"
        columnsRef="businessParameters" :onRowSelectChange="selectChangeHandle" :isSelectColumn="false"
        :onColumnsChange="columns => (this.columns = columns)">
        <template slot="controls" slot-scope="props">
          <multiuse-button size="small" type="primary" @click="addHandle(1)">新增</multiuse-button>

        </template>
      </FilterTables>
    </Spin>

    <!-- <BaseDialog :visible.sync="issearch" :title="'经销商查询'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ownerSeacher :rowData="formData" @close="ownerClose" />
    </BaseDialog> -->
    <BaseDialog :visible.sync="visible" :title="'基本信息'" destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <childrenModel :rowData="formData" @close="emitcloseHandler" />
    </BaseDialog>
    <Drawer :visible.sync="addvisible" :width="'70%'" :title="'设置信息'" destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <addModel @close="addcloseHandler" />
    </Drawer>
  </div>
</template>
<script>
import { getList, getDealerUser } from '@/api/omSaleP/vehicleParameters/PlanOrderTime/index.js';
import { dictionary } from '@/utils/dictMixin';
import childrenModel from './childrenModel';
import { exportExcelFile } from '@/utils';
import addModel from './addModel';
export default {
  name: 'businessParameters',
  data() {
    // this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: getList,
      fetchParams: {
        xhrAbort: true
      },
      formData: {},
      visible: false,
      addvisible: false,
      importVisible: false,
      issearch: false,
      exportLoading: false,
    };
  },
  mixins: [dictionary],
  components: {
    childrenModel,
    addModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
    this.getUser();
  },
  methods: {
    createdFrom() {
      return [
        {
          type: 'SELECT',
          label: '设置类型',
          fieldName: 'setType',
          placeholder: '请选择',
          itemList: this.createDictList('2110')
          // .filter(x => x.value != 24201003).filter(x => x.value != 24201004),
          // initialValue: 24201001,
          // rules: [{ required: true, message: '请选择', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '创建人',
          fieldName: 'createdBy',
          placeholder: '请选择',
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '状态',
          fieldName: 'state',
          placeholder: '请选择',
          itemList: this.createDictList('1003'),
          // initialValue: 10031001,
          // rules: [{ required: true, message: '请选择', trigger: 'change' }]
        },
        {
          type: 'RANGE_DATE',
          label: '创建日期',
          fieldName: 'createdAtS|createdAtE',
          placeholder: '请选择',
          initialValue: [],
          dateType: 'exactdaterange'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 80,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 1)}>
                  编辑
                </multiuse-button>
              </div>
            );
          },
        },
        // {
        //   title: '编号',
        //   dataIndex: 'No',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '设置类型',
          dataIndex: 'setType',
          sorter: true,
          filter: true,
          filterType: 'input',
          filterItems: this.createDictList('2110'),
          render: props => {
            return <span>{this.createDictText(props.row.setType, '2110')}</span>;
          }
        },
        {
          title: '状态',
          dataIndex: 'state',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1003'),
          render: p => {
            return <span>{this.createDictText(p.row.state, '1003')}</span>;
          }
        },
        {
          title: '年月',
          dataIndex: 'yearMonth',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开始日期',
          dataIndex: 'begDay',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '结束日期',
          dataIndex: 'endDay',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '创建人',
          dataIndex: 'createdName',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '创建时间',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '更新人',
          dataIndex: 'updatedName',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '更新时间',
          dataIndex: 'updatedAt',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

      ];
    },
    selectChangeHandle(row) { },
    seacherFun() {
      this.issearch = true;
    },
    ownerClose(val, data) {
    
      if (data) {
        let dealerCodes = [];
        data.map((x) => {
          dealerCodes.push(x.dealerCode);
        });
        this.topFilterList.find((x) => x.fieldName == 'dealerCode').initialValue = dealerCodes.toString();
      }
      this.issearch = false;
    },
    addHandle(type) {
      if (type == 1) {
        this.addvisible = true;
      } else {
        this.importVisible = true;
      }
    },
    changeHandle(params) {
      this.fetchParams.xhrAbort = false;
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    editHandle(data, type) {
      this.formData = data;
    
      if (type == 1) {
        this.visible = true;
      } else {
        this.addvisible = true;
      }
    },
    // editHandle(data) {
    //   this.formData = data;
    //   this.visible = true;
    // },
    addcloseHandler(val) {
      this.addvisible = false;
      if (val) {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    emitcloseHandler(val) {
      this.visible = false;
      if (val) {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    importcloseHandler() {
      this.importVisible = false;
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    async getUser() {
      let res = await getDealerUser();
      let empList = res.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns.find(item => item.dataIndex === 'createdBy').editItems = empList; //操作姓名
      this.columns.find(item => item.dataIndex === 'createdBy').filterItems = empList;
      this.columns.find(item => item.dataIndex === 'updatedBy').editItems = empList; //操作姓名
      this.columns.find(item => item.dataIndex === 'updatedBy').filterItems = empList;
    }
  }
};
</script>
